'use strict';
//引入模块
var fs = require('fs');
var xml2js = require('xml2js');
//var Promise = require('any-promise');
var Promise = require('bluebird')
//读取票据信息
exports.readFileAsync = function(fpath, encoding) {
    return new Promise(function(resolve, reject) {
        fs.readFile(fpath, encoding, function(err, content) {
            if (err) {
                reject(err);
            }else{
                
                resolve(content);
            };
        });
    });
};
//写入票据信息
exports.writeFileAsync = function(fpath, content) {
    return new Promise(function(resolve, reject) {
        fs.writeFile(fpath, content, function(err) {
            if (err) {
                reject(err);
            }else{
                resolve();
            };
        });
    });
};

exports.parseXMLAsync = function(xml) {
    return new Promise(function(resolve, reject) {
        xml2js.parseString(xml, {
            trim: true,
            explicitArray: false
        }, function(err, content) {
            if (err) {
                reject(err);
            }
            resolve(content);
        });
    });
};